package com.service.atf.reply.service;

import com.service.atf.base.exception.TFException;
import com.service.atf.base.model.Account;
import com.service.atf.base.model.TFLogout;
import com.service.atf.base.utils.ATFConstants;
import com.service.atf.base.utils.ATFLogger;
import com.service.atf.reply.ac.AccountManager;
import com.service.atf.reply.core.IReadExecutor;

import java.util.Map;

/**
 * User: luotao
 * Date: 12-3-21
 * Time: 16:41:00
 */
public class LogoutService6 implements IReadExecutor<TFLogout> {
    @Override
    public boolean isNotify() {
        return true;
    }

    @Override
    public void initOut(Map out) {

    }

    @Override
    public void execute(boolean recover, AccountManager accountManager, TFLogout logout, Map out) {
        // Validata.validataToken(this,logout.getToken());
        // Validata.validataCustomerCode(this, logout.getCustomerCode());

        Account account = accountManager.getBussAccount(logout.getCustomerCode());
        //   Validata.validataACNull(this,logout.getCustomerCode(),account);

        //  Validata.validataToken(this, account.getToken());
        if (!logout.getToken().equals(account.getToken())) {
            String msg = "�û�token����" + logout.getCustomerCode();
            ATFLogger.syserr(msg);
            throw new TFException(ATFConstants.ATF_TOKEN_TIMEOUT, msg);
        }


        /*
       * REPLY�У�����ֶ��ά�����Ͷ����˻�����Ϊ�գ��򽫴�����Ϣ��¼����־��
       * <p/>
       * REPLY�У�������� =  ������� + ��ʱ��������AC�е��˻���Ϣд����ݿ�
       * �����û���¼״̬��Ϊ�Եǳ���ɾ��AC�и����û�����Ϣ
       * */
        /* if(account.getFrezAward()!=0||account.getFrezCharge()!=0){
          ATFLogger.syserr("�˻��еĶ��ά��Ͷ����ֵ��Ϊ0��custid : "
              +account.getCustomerCode()+" frezAward : "+account.getFrezAward()+
              " frazCharge : "+account.getFrezCharge());
        }*/
        account.setBalcCharge(account.getBalcCharge() + account.getFrezCharge());
        account.setBalcAward(account.getBalcAward() + account.getFrezAward());
        //����ʱ����ӵ����������
        account.addBalanceAward();
        /*CustDBService customerDBService=(CustDBService)Bootup.getAttribute(GlobalDefine.ATF_DB_KEY_CUST);

           String sql = "update ELMP_TRANS_CUSTOM set "
            +"CUSTOMWINBALANCE = "+account.getBalcAward()
            +",CUSTOMBALANCE = "     +account.getBalcCharge()
            +",DAILYCHARGECOUNT = "     +account.getTotalCountCharge()
            +",DAILYCHARGEAMOUNT = "    +account.getTotalCharge()
            +",DAILYCASHCOUNT = "       +account.getTotalCountCash()
            +",DAILYCASHAMOUNT = "      +account.getTotalCash()
            +",DAILYSALECOUNT = "       +account.getTotalCountSale()
            +",DAILYSALEAMOUNT = "      +account.getTotalSale()
            +",DAILYGAMETIME = "        +account.getTotalGameTime()
            +",CUSTOMISLOGIN = 1 where CUSTOMCODE = '"+ account.getCustomerCode()+"'"
            ;
        System.out.println("sql = "+sql);
        UResults uResults = customerDBService.updateCustomerParam(account);
        if(!uResults.success()){
          String msg = "�û��˳�ʱ�޸���ݿ����˻��������"+logout.getCustomerCode();
          ATFLogger.syserr(msg);
          throw new TFException(GlobalErrors.ATF_LOGOUT_DB_ERR,msg);
        }
        //ɾ��AC�еĴ����˻���Ϣ
        accountManager.removeCustomer(account.getCustomerCode());*/

    }
}
